package demogeric;

import java.util.Objects;

class Food {

}
class Fruit extends Food {

}
class Apple extends Fruit {

}
class Banana extends Fruit {

}

class Plate<T> {
    private T data;

    public T getDate() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}

public class Test3 {

    public static void main(String[] args) {
        Plate<Food> plate1 = new Plate<>();
        plate1.setData(new Food());

        func2(plate1);

        //demogeric.Fruit fruit = (demogeric.Fruit)new demogeric.Food();

        //demogeric.Food food = new demogeric.Fruit();
        //demogeric.Fruit fruit = (demogeric.Fruit)food;
    }

    public static void func2(Plate<? super Fruit> pa) {
        pa.setData(new demogeric.Apple());
        pa.setData(new demogeric.Banana() );

        demogeric.Fruit fruit = (demogeric.Fruit)pa.getDate();
        Object o = pa.getDate();
        System.out.println(o);
    }

    public static void main1(String[] args) {
        Plate<Apple> plate1 = new Plate<>();
        plate1.setData(new Apple());

        Plate<Banana> plate2 = new Plate<>();
        plate2.setData(new Banana());

        func(plate1);
        func(plate2);

    }

    public static void func(Plate<? extends Fruit> pa) {
        //pa.setData(new demogeric.Apple());
        //pa.setData(new demogeric.Banana());//不能知道 此时传入的是哪个子类

        Fruit fruit = pa.getDate();
        System.out.println(fruit);
    }
}
